﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyVoteMVC.Web.Extensions
{
    public static class SubmitChecker
    {
        static readonly string lastSubmitTime = "lastSubmitTime";
        public static bool SubmitFreCheck()
        {
            if (CurrentContext().Session[lastSubmitTime] is DateTime)
            {
                var date = (DateTime)CurrentContext().Session[lastSubmitTime];
                if (date.AddSeconds(5) > DateTime.Now)
                    return true;
            }
            return false;
        }

        public static void SetLastSubmitDate()
        {
            CurrentContext().Session[lastSubmitTime] = DateTime.Now;
        }

        public static HttpContext CurrentContext()
        {
            return HttpContext.Current;
        }
    }
}